<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
                "http://www.w3.org/TR/REC-html40/loose.dtd">
<html>
<head>
  <title>Description of image_resize</title>
  <meta name="keywords" content="image_resize">
  <meta name="description" content="image_resize - resize an image using bicubic interpolation">
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  <meta name="generator" content="m2html &copy; 2005 Guillaume Flandin">
  <meta name="robots" content="index, follow">
  <link type="text/css" rel="stylesheet" href="../../m2html.css">
  <script type="text/javascript">
    if (top.frames.length == 0) { top.location = "../../index.html"; };
  </script>
</head>
<body>
<a name="_top"></a>
<!-- ../menu.html VMT_4.0_dev --><!-- menu.html utils -->
<h1>image_resize
</h1>

<h2><a name="_name"></a>PURPOSE <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2>
<div class="box"><strong>image_resize - resize an image using bicubic interpolation</strong></div>

<h2><a name="_synopsis"></a>SYNOPSIS <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2>
<div class="box"><strong>function newimg = image_resize(img,p1,q1,r1) </strong></div>

<h2><a name="_description"></a>DESCRIPTION <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2>
<div class="fragment"><pre class="comment"> image_resize - resize an image using bicubic interpolation

   newimg = image_resize(img,nx,ny,nz);
 or
   newimg = image_resize(img,newsize);

   Works for 2D, 2D 2 or 3 channels, 3D images.

   Copyright (c) 2004 Gabriel Peyr</pre></div>

<!-- crossreference -->
<h2><a name="_cross"></a>CROSS-REFERENCE INFORMATION <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2>
This function calls:
<ul style="list-style-image:url(../../matlabicon.gif)">
<li><a href="image_resize.html" class="code" title="function newimg = image_resize(img,p1,q1,r1)">image_resize</a>	image_resize - resize an image using bicubic interpolation</li></ul>
This function is called by:
<ul style="list-style-image:url(../../matlabicon.gif)">
<li><a href="image_resize.html" class="code" title="function newimg = image_resize(img,p1,q1,r1)">image_resize</a>	image_resize - resize an image using bicubic interpolation</li></ul>
<!-- crossreference -->



<h2><a name="_source"></a>SOURCE CODE <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2>
<div class="fragment"><pre>0001 <a name="_sub0" href="#_subfunctions" class="code">function newimg = image_resize(img,p1,q1,r1)</a>
0002 
0003 <span class="comment">% image_resize - resize an image using bicubic interpolation</span>
0004 <span class="comment">%</span>
0005 <span class="comment">%   newimg = image_resize(img,nx,ny,nz);</span>
0006 <span class="comment">% or</span>
0007 <span class="comment">%   newimg = image_resize(img,newsize);</span>
0008 <span class="comment">%</span>
0009 <span class="comment">%   Works for 2D, 2D 2 or 3 channels, 3D images.</span>
0010 <span class="comment">%</span>
0011 <span class="comment">%   Copyright (c) 2004 Gabriel Peyr</span>
0012 
0013 <span class="keyword">if</span> nargin==2
0014     <span class="comment">% size specified as an array</span>
0015     q1 = p1(2);
0016     <span class="keyword">if</span> length(p1)&gt;2
0017         r1 = p1(3);
0018     <span class="keyword">else</span>
0019         r1 = size(img,3);
0020     <span class="keyword">end</span>
0021     p1 = p1(1);        
0022 <span class="keyword">end</span>
0023 
0024 <span class="keyword">if</span> nargin&lt;4
0025     r1 = size(img,3);
0026 <span class="keyword">end</span>
0027 
0028 <span class="keyword">if</span> ndims(img)&lt;2 || ndims(img)&gt;3
0029     error(<span class="string">'Works only for grayscale or color images'</span>);
0030 <span class="keyword">end</span>
0031 
0032 <span class="keyword">if</span> ndims(img)==3 &amp;&amp; size(img,3)&lt;4
0033     <span class="comment">% RVB image</span>
0034     newimg = zeros(p1,q1, size(img,3));
0035     <span class="keyword">for</span> m=1:size(img,3)
0036         newimg(:,:,m) = <a href="image_resize.html" class="code" title="function newimg = image_resize(img,p1,q1,r1)">image_resize</a>(img(:,:,m), p1, q1);
0037     <span class="keyword">end</span>
0038     <span class="keyword">return</span>;
0039 <span class="keyword">elseif</span> ndims(img)==3
0040     p = size(img,1);
0041     q = size(img,2);
0042     r = size(img,3);
0043     [Y,X,Z] = meshgrid( (0:q-1)/(q-1), (0:p-1)/(p-1), (0:r-1)/(r-1)  );
0044     [YI,XI,ZI] = meshgrid( (0:q1-1)/(q1-1), (0:p1-1)/(p1-1), (0:r1-1)/(r1-1) );
0045     newimg = interp3( Y,X,Z, img, YI,XI,ZI ,<span class="string">'nearest'</span>);
0046     <span class="keyword">return</span>;
0047 <span class="keyword">end</span>
0048 
0049 p = size(img,1);
0050 q = size(img,2);
0051 [Y,X] = meshgrid( (0:q-1)/(q-1), (0:p-1)/(p-1) );
0052 [YI,XI] = meshgrid( (0:q1-1)/(q1-1), (0:p1-1)/(p1-1) );
0053 newimg = interp2( Y,X, img, YI,XI,<span class="string">'nearest'</span>);</pre></div>
<hr><address>Generated on Thu 21-Mar-2013 09:32:01 by <strong><a href="http://www.artefact.tk/software/matlab/m2html/" target="_parent">m2html</a></strong> &copy; 2005</address>
</body>
</html>